#include <math.h>
#include "report.h"
#include "bernoulli.h"

int main(int argc, char ** argv)
{
  Bernoulli_t poi;
  Report_Real_t stats;
  double avg, sd;
  int i;

  Bernoulli_Init_Params(&poi, 1, 0.6);     /* the decimal point is CRITICAL */
  
  Report_Real_Init(&stats);

  for (i=0; i<100000; i++)
  {
    int val; 
    val = Bernoulli_Sample(&poi, 0);
    Report_Real_Update(&stats, (double) 1 - val);
  }
  
  Report_Real_Compute(&stats, &avg, &sd);
  
  if (fabs(avg - .6) > .1)
    return 1;
  
  if (fabs(sd*sd - .24) > .1)
    return 2;

  /* true */

  if (fabs(.6 - Bernoulli_Prob(&poi, 0, 0)) > .1)
    return 3;

  if (fabs(log(.6) - Bernoulli_LogProb(&poi, 0, 0)) > .1)
    return 4;

  /* false */

  if (fabs(.4 - Bernoulli_Prob(&poi, 1, 0)) > .1)
    return 5;

  if (fabs(log(.4) - Bernoulli_LogProb(&poi, 1, 0)) > .1)
    return 6;

  return 0;
}
